package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.rpc.protocol.redis.RedisProtocol;
import com.qingcheng.entity.Result;
import com.qingcheng.pojo.comment.Comment;
import com.qingcheng.pojo.comment.Reply;
import com.qingcheng.service.comment.CommentService;
import com.qingcheng.service.comment.ReplyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/reply")
public class ReplyController {
    @Reference
    private ReplyService replyService;
    @Reference
    private CommentService commentService;

    @GetMapping("findAllByCommentId")
    public Map<String,Object> findAllByCommentId(String commentId){
        //创建Map
        Map<String,Object> map=new HashMap<>();
        //查询原评论
        Comment comment = commentService.findOneById(commentId);
        //查询评论评价
        List<Reply> replyList = replyService.findAllByCommentId(commentId);
        //存入数据
        map.put("comment",comment);
        map.put("replyList",replyList);
        return map;

    }
    @PostMapping("/add")
    public Result add(@RequestBody Reply reply){
        //String username = SecurityContextHolder.getContext().getAuthentication().getName();
        String username="吴彦祖";
        reply.setUsername(username);
        replyService.add(reply);
        return new Result();
    }


}
